package com.ruoyi.project.goods.billHead.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.goods.billHead.domain.GoodsBillHead;
import com.ruoyi.project.goods.billHead.service.IGoodsBillHeadService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 发货单明细Controller
 * 
 * @author lonsn
 * @date 2021-05-19
 */
@Controller
@RequestMapping("/goods/billHead")
public class GoodsBillHeadController extends BaseController
{
    private String prefix = "goods/billHead";

    @Autowired
    private IGoodsBillHeadService goodsBillHeadService;

    @RequiresPermissions("goods:billHead:view")
    @GetMapping()
    public String billHead()
    {
        return prefix + "/billHead";
    }

    /**
     * 查询发货单明细列表
     */
    @RequiresPermissions("goods:billHead:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodsBillHead goodsBillHead)
    {
        startPage();
        List<GoodsBillHead> list = goodsBillHeadService.selectGoodsBillHeadList(goodsBillHead);
        return getDataTable(list);
    }

    /**
     * 导出发货单明细列表
     */
    @RequiresPermissions("goods:billHead:export")
    @Log(title = "发货单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsBillHead goodsBillHead)
    {
        List<GoodsBillHead> list = goodsBillHeadService.selectGoodsBillHeadList(goodsBillHead);
        ExcelUtil<GoodsBillHead> util = new ExcelUtil<GoodsBillHead>(GoodsBillHead.class);
        return util.exportExcel(list, "billHead");
    }

    /**
     * 新增发货单明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存发货单明细
     */
    @RequiresPermissions("goods:billHead:add")
    @Log(title = "发货单明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodsBillHead goodsBillHead)
    {
        return toAjax(goodsBillHeadService.insertGoodsBillHead(goodsBillHead));
    }

    /**
     * 修改发货单明细
     */
    @GetMapping("/edit/{billHeadId}")
    public String edit(@PathVariable("billHeadId") Long billHeadId, ModelMap mmap)
    {
        GoodsBillHead goodsBillHead = goodsBillHeadService.selectGoodsBillHeadById(billHeadId);
        mmap.put("goodsBillHead", goodsBillHead);
        return prefix + "/edit";
    }

    /**
     * 修改保存发货单明细
     */
    @RequiresPermissions("goods:billHead:edit")
    @Log(title = "发货单明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodsBillHead goodsBillHead)
    {
        return toAjax(goodsBillHeadService.updateGoodsBillHead(goodsBillHead));
    }

    /**
     * 删除发货单明细
     */
    @RequiresPermissions("goods:billHead:remove")
    @Log(title = "发货单明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(goodsBillHeadService.deleteGoodsBillHeadByIds(ids));
    }
}
